package reflects

import (
	"gitee.com/injoyai/goutil/chans"
	"gitee.com/injoyai/goutil/maps"
	"gitee.com/injoyai/goutil/string/logs/v1"
	"reflect"
)

type A struct {
	P    *string
	Name string `i:"name;haha"`
	Age  int    ``
	List []string

	small bool
}

func (this *A) fun() {}

type IA interface {
}

func Test() {
	logs.Test(New(&A{Name: "test"}).GetTag(1, "i"))
	return

	data := A{Name: "test"}
	key := reflect.TypeOf(data)
	val := reflect.ValueOf(data)

	//logs.Test(key.NumField())
	//logs.Test(val.NumField())

	logs.Test(val.String())
	logs.Test(val.CanInterface(), val.Interface())
	logs.Test(val.CanAddr())
	logs.Test(val.CanSet())

	for i := range chans.Count(key.NumField()) {
		logs.Test("---------------------------")
		logs.Test("IsValid:", val.FieldByIndex([]int{i}).IsValid())
		logs.Test("IsZero:", val.FieldByIndex([]int{i}).IsZero())
		//logs.Test("IsNil:", val.FieldByIndex([]int{i}).IsNil())
		if val.FieldByIndex([]int{i}).CanInterface() {
			logs.Test("key:", key.FieldByIndex([]int{i}).Name)
			logs.Test("val:", val.FieldByIndex([]int{i}).Interface())
			logs.Test("tag:", key.FieldByIndex([]int{i}).Tag)

		}
	}

	return

	//去掉指针
	//去掉小写字段
	//x := reflect.ValueOf()
	//logs.Test(x.String())
	//logs.Test(x.Interface())
	//for i := range tool.Count(x.NumField()) {
	//	logs.Test(x.FieldByIndex([]int{i}).Kind().String())
	//	logs.Test(x.FieldByIndex([]int{i}))
	//	logs.Test(x.FieldByIndex([]int{i}).Type())
	//	logs.Test(x.FieldByIndex([]int{i}).Interface())
	//}
	//return

	r := reflect.TypeOf(maps.Take()) //A{Name: "test"})
	logs.Test(r.String())            //包名.结构名:reflects.A
	logs.Test(r.Name())              //结构名:A
	logs.Test(r.Elem())
	logs.Test(r.Kind().String()) //类型:struct
	logs.Test(r.NumField())
	logs.Test(r.PkgPath())
	//logs.Test(r.Key())
	//logs.Test(r.Len())
	//logs.Test(r.Size())
	//logs.Test(r.Align())
	//logs.Test(r.Bits())
	logs.Test(r.Comparable())
	logs.Test(r.FieldAlign())
	for i := range chans.Count(r.NumField()) {
		logs.Test(r.FieldByIndex([]int{i}).Name)      //字段名称
		logs.Test(r.FieldByIndex([]int{i}).Type)      //字段类型
		logs.Test(r.FieldByIndex([]int{i}).Offset)    //偏移
		logs.Test(r.FieldByIndex([]int{i}).Index)     //字段下标
		logs.Test(r.FieldByIndex([]int{i}).Tag)       //字段tag
		logs.Test(r.FieldByIndex([]int{i}).Anonymous) //是否隐藏字段
		logs.Test(r.FieldByIndex([]int{i}).PkgPath)   //位置
	}

}

/*



 */
